/**
* @Title: warning_ctrl.js
* @Description: TODO
* Copyright: Copyright (c) 2014 
 * Company:中国平安
*
* @Project HIMS-FWA
* @date 2014年10月27日 下午4:43:38
* @version V1.0
*/
;
(function(){
	'use strict';
	
	var app = angular.module('fwa.mainApp');
	app.controller('WarningCtrl', ['$scope','FwaTabsetService','$modal','BaseURL','Modal','WarningService',
	                                function($scope,FwaTabsetService,$modal,baseUrl,Modal,WarningService){
		$scope.warningService = WarningService;
		WarningService.initMedicalOrgInfoList();
		WarningService.getActinstList();
		$scope.form = {};
//		$scope.form.happenDate = {};
		var currentPage = 1;
		var cellTemplate = 
			'<td>'+
				'<a  ng-click="clickLink(\'warning.warningEdit\',data)" ng-show="data.tranName== \'分析\' || data.tranName== \'提交\'">{{data.tranName}}</a>'+
				'<a  ng-click="clickLink(\'\',data)" ng-show="data.tranName== \'修改\'">{{data.tranName}}</a>'+
				'<a  ng-click="clickLink(\'warning.warningInitialAudit\',data)" ng-show="data.tranName== \'审核\'">{{data.tranName}}</a>'+
				'<a  ng-click="clickLink(\'warning.warningAuditConfirm\',data)" ng-show="data.tranName== \'确认\'">{{data.tranName}}</a>'+
				'<a  ng-click="clickLink(\'\',data)" ng-show="data.tranName== \'审定\'">{{data.tranName}}</a>'+
				'<a  ng-click="clickLink(\'\',data)" ng-show="data.tranName== \'审批\'">{{data.tranName}}</a>'+
				'<a  ng-click="clickLink(\'warning.warningAuditQuery\',data)" ng-show="data.tranName== \'查看\'">{{data.tranName}}</a>'+
			'</td>',
			indexNo = '<td>'+
				'{{$index+1}}'+
			'</td>';
       $scope.columns = [
        {label:'预警编号',map:'warnNo',width:'10%'},
        {label:'预警事件名称',map:'summary',width:'10%'},
        {label:'机构名称',map:'medicalOrgName',width:'10%'},
        {label:'处理方式',map:'process',width:'8%'},
        {label:'预警时段',map:'happenDate',width:'14%'},
        {label:'反馈截止时间',map:'feedbackEndDate',width:'10%'},
        {label:'受理时间',map:'warnDate',width:'10%'},
        {label:'审核时间',map:'auditDate',width:'10%'},
        {label:'事件状态',map:'actName',width:'10%'},
        {label:'操作',width:'8%',cellClass:'text-left', cellTemplate:cellTemplate}];
       
       $scope.clickLink = function (url,data){
    	   FwaTabsetService.selectTab(url,{warnNo:data.warnNo,actNo:data.actNo},false);
       }
       $scope.addclickLink = function (){
    	   FwaTabsetService.selectTab('warning.warningAdd',null,false);
       }
		//每页显示数
        var start = 0,
            limit = 20;
        
//        $scope.form = {
//            page:"0",
//            pageSize:"20"
//        };

        
        var params = function (){
			var warnNo=null;
			if($scope.form.warnNo&&!angular.isUndefined($scope.form.warnNo)){
				warnNo = $scope.form.warnNo;
			}
			var medicalOrgCode=null;
			if($scope.form.medicalOrgCode&&!angular.isUndefined($scope.form.medicalOrgCode)){
				medicalOrgCode = $scope.form.medicalOrgCode;
			}
			var summary=null;
			if($scope.form.summary&&!angular.isUndefined($scope.form.summary)){
				summary = $scope.form.summary;
			}
			var feedbackEndDate=null;
			if($scope.form.feedbackEndDate&&!angular.isUndefined($scope.form.feedbackEndDate)){
				feedbackEndDate = $scope.form.feedbackEndDate;
			}
			var actNo=null;
			if($scope.form.actNo&&!angular.isUndefined($scope.form.actNo)){
				actNo = $scope.form.actNo;
			}
//			var startDate=null;
//			if($scope.form.happenDate.start&&!angular.isUndefined($scope.form.happenDate.start)){
//				startDate = $scope.form.happenDate.start;
//			}
//			var endDate=null;
//			if($scope.form.happenDate.end&&!angular.isUndefined($scope.form.happenDate.end)){
//				endDate = $scope.form.happenDate.end;
//			}
//			
			if(parseInt(currentPage) > 1){
                  start = (parseInt(currentPage) - 1) * limit;
            }
			var params = {
					warnNo:warnNo,
					medicalOrgCode:medicalOrgCode,
					summary:summary,
					feedbackEndDate:feedbackEndDate,
					actNo:actNo,
//					startDate:startDate,
//					endDate:endDate,
					start:start,
					limit:limit
			}
			return params;
		}

		//查询
        $scope.$on('pageTool.skipPage',function(e,v){
            start = limit*(v-1);
            $scope.form.page = start;
            $scope.onSubmit();
        });

        
        $scope.onSubmit = function(){
        	WarningService.query(params()).success(function(res){
                $scope.tableData = res.result;
                $scope.totalCount = res.total;
            });
        };
        //加载数据
        $scope.onSubmit();
        
         //重置
        $scope.resetBut = function(){
			$scope.form = {};
//			$scope.form.happenDate = {};
            $scope.form.summary='';
            $scope.form.medicalOrgName='';
            $scope.form.feedbackEndDate='';
            $scope.form.actNo='';
		}
	}]);
})();